package chain.node;

import chain.Handler;
import chain.PaymentRequest;

// 检查余额的节点
public class BalanceChecker extends Handler {
    @Override
    public void handlePaymentRequest(PaymentRequest request) throws Exception {
        // rpc获取用户可用余额
        int amountAvailable = 1000;
        if (amountAvailable < request.getAmount()) {
            throw new Exception("balance check fail, amountAvailable: " + amountAvailable);
        }
        System.out.println("balance check success");
        if (nextHandler != null) {
            nextHandler.handlePaymentRequest(request);
        }
    }
}
